<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xf="http://www.w3.org/2002/xforms">
    <head>
        <title>Cron User Interface</title>
        <link type="text/css" rel="stylesheet" href="/exist/rest/db/syntactica/resources/css/style.css"/>
        <link type="text/css" rel="stylesheet" href="/exist/rest/db/syntactica/resources/css/xforms.css"/>
        <style type="text/css">
         <![CDATA[

         @namespace xf url("http://www.w3.org/2002/xforms");
         body {
            font-family: Helvetica, sans-serif;
         }
        
         xf|output &gt;
         xf|label, xf|select &gt;
         xf|label {
            font-weight: bold;
         }
        
         .table-container {
       display: table-row;
         }
        
         .table-cell {
              display: table-cell;
              vertical-align: top;
              width: 70px;
              height: 30px;
         }
 
         ]]></style>
        <xf:model>
            <xf:instance xmlns="" id="save-data">
                <data>
                    <seconds>
                        <label>1</label>
                        <value>1</value>
                    </seconds>
                    <minutes>
                        <label>1</label>
                        <value>1</value>
                    </minutes>
                    <hours>
                        <label>1</label>
                        <value>1</value>
                    </hours>
                    <day-of-month>
                        <label>1</label>
                        <value>1</value>
                    </day-of-month>
                    <month>
                        <label>All</label>
                        <value>*</value>
                    </month>
                    <day-of-week>
                        <label>Monday</label>
                        <value>1</value>
                    </day-of-week>
                    <year>
                        <label/>
                        <value/>
                    </year>
                </data>
            </xf:instance>
          
            <xf:instance xmlns="" id="tmp">
                <data>
                   <sec1/>
                   <sec2/>
                   <sec3/>
                   <sec4/>
                   <sec5/>
                   <sec6/>
                   <min1/>
                   <min2/>
                   <min3/>
                   <min4/>
                   <min5/>
                   <min6/>
                   <hour1/>
                   <hour2/>
                   <day-of-month1/>
                   <day-of-month2/>
                   <day-of-month3/>
                </data>
            </xf:instance>
          
           <!-- concat all six columns for seconds -->
            <xf:bind nodeset="instance('save-data')/seconds/value" calculate="concat(instance('tmp')/sec1, ' ', instance('tmp')/sec2, ' ',               instance('tmp')/sec3, ' ', instance('tmp')/sec4,' ', instance('tmp')/sec5, ' ',               instance('tmp')/sec6)"/>
          
           <!-- concat all six columns or minutes-->
            <xf:bind nodeset="instance('save-data')/minutes/value" calculate="concat(instance('tmp')/min1, ' ', instance('tmp')/min2, ' ',               instance('tmp')/min3, ' ', instance('tmp')/min4,' ', instance('tmp')/min5, ' ',               instance('tmp')/min6)"/>
 
           <!-- concat two  columns for hours-->
           <xf:bind nodeset="instance('save-data')/hours/value"
           calculate="concat(instance('tmp')/hour1, ' ', instance('tmp')/hour2)"/>
          
           <!-- concat three columns for day-of-month-->
           <xf:bind nodeset="instance('save-data')/day-of-month/value"
              calculate="concat(instance('tmp')/day-of-month1, ' ', instance('tmp')/day-of-month2, ' ', instance('tmp')/day-of-month3)"/>
          
           <!-- all the fields are required except the year -->
            <xf:bind nodeset="instance('save-data')/seconds/value" required="true()"/>
            <xf:bind nodeset="instance('save-data')/minutes/value" required="true()"/>
            <xf:bind nodeset="instance('save-data')/hours/value" required="true()"/>
            <xf:bind nodeset="instance('save-data')/day-of-mont/value" required="true()"/>
            <xf:bind nodeset="instance('save-data')/month/value" required="true()"/>
            <xf:bind nodeset="instance('save-data')/day-of-week/value" required="true()"/>
            <xf:instance xmlns="" id="code-table" src="../code-tables/code-tables.xml"/>
            <xf:submission id="echo" method="post" action="echo.xq"/>
            <xf:submission ref="instance('code-table')/code[code-name='seconds']" id="echo-codes" method="post" action="echo.xq"/>
            <xf:submission id="save" method="post" action="save.xq"/>
        </xf:model>
    </head>
    <body>
        <h1>Job Scheduler</h1>
        <xf:switch>
          <!-- initially, only the label and the read-only value is visible in the first case -->
            <xf:case id="seconds-hide">
                <xf:output ref="instance('save-data')/seconds/value">
                    <xf:label>Current Seconds:</xf:label>
                </xf:output>
                <xf:trigger>
                    <xf:label>Set Seconds + </xf:label>
                    <xf:toggle case="seconds-unhide" ev:event="DOMActivate"/>
                </xf:trigger>
            </xf:case>
          <!-- if you click on the trigger called "Set Months" the full control will be visible -->
            <xf:case id="seconds-unhide">
                <xf:label>Select Seconds:</xf:label>
                <br/>
                <div class="table-container ">
                    <xf:select ref="instance('tmp')/sec1" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 0) and (position() &lt; 11)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/sec2" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 10) and (position() &lt; 21)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/sec3" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 20) and (position() &lt; 31)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/sec4" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 30) and (position() &lt; 41)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/sec5" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 40) and (position() &lt; 51)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/sec6" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 50) and (position() &lt; 61)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                </div>
             <!-- once you have selected all the months in the control you can hide the control again -->
                <xf:trigger>
                    <xf:label>Hide Seconds</xf:label>
                    <xf:toggle case="seconds-hide" ev:event="DOMActivate"/>
                </xf:trigger>
                <br/>
                <xf:input ref="instance('save-data')/seconds/value">
                    <xf:label>Seconds:</xf:label>
                </xf:input>
            </xf:case>
        </xf:switch>
      
      
        <xf:switch>
          <!-- initially, only the label and the read-only value is visible in the first case -->
            <xf:case id="minutes-hide">
                <xf:output ref="instance('save-data')/minutes/value">
                    <xf:label>Current Minutes:</xf:label>
                </xf:output>
                <xf:trigger>
                    <xf:label>Set Minutes + </xf:label>
                    <xf:toggle case="minutes-unhide" ev:event="DOMActivate"/>
                </xf:trigger>
            </xf:case>
          <!-- if you click on the trigger called "Set Months" the full control will be visible -->
            <xf:case id="minutes-unhide">
               <xf:label>Set Minutes:</xf:label>
                <div class="table-container ">
                    <xf:select ref="instance('tmp')/min1" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 0) and (position() &lt; 11)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/min2" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 10) and (position() &lt; 21)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/min3" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 20) and (position() &lt; 31)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/min4" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 30) and (position() &lt; 41)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/min5" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 40) and (position() &lt; 51)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                    <xf:select ref="instance('tmp')/min6" appearance="full" class="table-cell">
                        <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 50) and (position() &lt; 61)]">
                            <xf:label ref="value"/>
                            <xf:value ref="value"/>
                        </xf:itemset>
                    </xf:select>
                </div> <!-- end of table -->
                <xf:trigger>
                    <xf:label>Hide Minutes</xf:label>
                    <xf:toggle case="minutes-hide" ev:event="DOMActivate"/>
                </xf:trigger>
                <br/>
                <xf:input ref="instance('save-data')/minutes/value">
                    <xf:label>Minutes:</xf:label>
                </xf:input>
            </xf:case>
        </xf:switch>
      
  
       <xf:switch>
          <!-- initially, only the label and the read-only value is visible in the first case -->
          <xf:case id="hours-hide">
             <xf:output ref="instance('save-data')/hours/value">
                <xf:label>Current Hour:</xf:label>
             </xf:output>
             <xf:trigger>
                <xf:label>Set Hour + </xf:label>
                <xf:toggle case="hours-unhide" ev:event="DOMActivate"/>
             </xf:trigger>
          </xf:case>
          <!-- if you click on the trigger called "Set Months" the full control will be visible -->
          <xf:case id="hours-unhide">
             <xf:label>Set Hour:</xf:label>
             <div class="table-container ">
                <xf:select ref="instance('tmp')/hour1" appearance="full" class="table-cell">
                   <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 0) and (position() &lt; 13)]">
                      <xf:label ref="value"/>
                      <xf:value ref="value"/>
                   </xf:itemset>
                </xf:select>
                <xf:select ref="instance('tmp')/hour2" appearance="full" class="table-cell">
                   <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 13) and (position() &lt; 25)]">
                      <xf:label ref="value"/>
                      <xf:value ref="value"/>
                   </xf:itemset>
                </xf:select>
             </div> <!-- end of table -->
             <xf:trigger>
                <xf:label>Hide Hours</xf:label>
                <xf:toggle case="hours-hide" ev:event="DOMActivate"/>
             </xf:trigger>
             <br/>
             <xf:input ref="instance('save-data')/hours/value">
                <xf:label>Hours:</xf:label>
             </xf:input>
          </xf:case>
       </xf:switch>
      


       <xf:switch>
          <!-- initially, only the label and the read-only value is visible in the first case -->
          <xf:case id="day-of-month-hide">
             <xf:output ref="instance('save-data')/day-of-month/value">
                <xf:label>Current Day of Month:</xf:label>
             </xf:output>
             <xf:trigger>
                <xf:label>Set Day of Month + </xf:label>
                <xf:toggle case="day-of-month-unhide" ev:event="DOMActivate"/>
             </xf:trigger>
          </xf:case>
          <!-- if you click on the trigger called "Set Months" the full control will be visible -->
          <xf:case id="day-of-month-unhide">
             <xf:label>Set Day of Month:</xf:label>
             <div class="table-container ">
                <xf:select ref="instance('tmp')/day-of-month1" appearance="full" class="table-cell">
                   <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 1) and (position() &lt; 12)]">
                      <xf:label ref="value"/>
                      <xf:value ref="value"/>
                   </xf:itemset>
                </xf:select>
                <xf:select ref="instance('tmp')/day-of-month2" appearance="full" class="table-cell">
                   <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 11) and (position() &lt; 22)]">
                      <xf:label ref="value"/>
                      <xf:value ref="value"/>
                   </xf:itemset>
                </xf:select>
                <xf:select ref="instance('tmp')/day-of-month3" appearance="full" class="table-cell">
                   <xf:itemset nodeset="instance('code-table')/code[code-name='seconds']/items/item[(position() &gt; 21) and (position() &lt; 33)]">
                      <xf:label ref="value"/>
                      <xf:value ref="value"/>
                   </xf:itemset>
                </xf:select>
             </div> <!-- end of table -->
             <xf:trigger>
                <xf:label>Hide Day of Month</xf:label>
                <xf:toggle case="day-of-month-hide" ev:event="DOMActivate"/>
             </xf:trigger>
             <br/>
             <xf:input ref="instance('save-data')/day-of-month/value">
                <xf:label>Day of Month:</xf:label>
             </xf:input>
          </xf:case>
       </xf:switch>
      


        <xf:switch>
         <!-- initially, only the label and the read-only value is visible in the first case -->
            <xf:case id="month-hide">
                <xf:output ref="instance('save-data')/month/value">
                    <xf:label>Current Months:</xf:label>
                </xf:output>
                <xf:trigger>
                    <xf:label>Set Months</xf:label>
                    <xf:toggle case="month-unhide" ev:event="DOMActivate"/>
                </xf:trigger>
            </xf:case>
         <!-- if you click on the trigger called "Set Months" the full control will be visible -->
            <xf:case id="month-unhide">
                <xf:select ref="instance('save-data')/month/value" appearance="full">
                    <xf:label>Select Months</xf:label>
                    <xf:itemset nodeset="instance('code-table')/code[code-name='month']/items/item">
                        <xf:label ref="label"/>
                        <xf:value ref="value"/>
                    </xf:itemset>
                </xf:select>
            <!-- once you have selected all the months in the control you can hide the control again -->
                <xf:trigger>
                    <xf:label>Hide Month</xf:label>
                    <xf:toggle case="month-hide" ev:event="DOMActivate"/>
                </xf:trigger>
                <br/>
                <xf:input ref="instance('save-data')/month/value">
                    <xf:label>Month:</xf:label>
                </xf:input>
            </xf:case>
        </xf:switch>
        <xf:switch>
         <!-- initially, only the label and the read-only value is visible in the first case -->
            <xf:case id="day-of-week-hide">
                <xf:output ref="instance('save-data')/day-of-week/value">
                    <xf:label>Current Day of Week:</xf:label>
                </xf:output>
                <xf:trigger>
                    <xf:label>Set Day of Week</xf:label>
                    <xf:toggle case="day-of-week-unhide" ev:event="DOMActivate"/>
                </xf:trigger>
            </xf:case>
         <!-- if you click on the trigger called "Set Months" the full control will be visible -->
            <xf:case id="day-of-week-unhide">
                <xf:select ref="instance('save-data')/day-of-week/value" appearance="full">
                    <xf:label>Select Days of Week</xf:label>
                    <xf:itemset nodeset="instance('code-table')/code[code-name='day-of-week']/items/item">
                        <xf:label ref="label"/>
                        <xf:value ref="value"/>
                    </xf:itemset>
                </xf:select>
            <!-- once you have selected all the months in the control you can hide the control again -->
                <xf:trigger>
                    <xf:label>Hide Day of Week</xf:label>
                    <xf:toggle case="day-of-week-hide" ev:event="DOMActivate"/>
                </xf:trigger>
                <br/>
                <xf:input ref="instance('save-data')/day-of-week/value">
                    <xf:label>Month:</xf:label>
                </xf:input>
            </xf:case>
        </xf:switch>
      
       <xf:input ref="instance('save-data')/year/value">
          <xf:label>Year:</xf:label>
       </xf:input>
       <br/>
       <br/>
        <xf:submit submission="save">
            <xf:label>Save</xf:label>
        </xf:submit>
        <xf:submit submission="echo">
            <xf:label>Echo</xf:label>
        </xf:submit>
        <xf:submit submission="echo-codes">
            <xf:label>Echo Codes</xf:label>
        </xf:submit>
    </body>
</html>